package com.dy.controller;

import com.dy.pojo.dto.DyCommentDTO;
import com.dy.pojo.vo.DyCommentVO;
import com.dy.service.DyCommentService;
import com.dy.utils.ApiResousUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @ClassName:
 * @Author: 仄言in
 * @Desctiption: (描述)
 * @Date: 2021/6/10 11:20
 * @Version 1.0 (版本)
 */
@RestController
@RequestMapping("comment")
public class DyCommentController {
    @Autowired
    private DyCommentService dyCommentService;

    /**
     * 查看评论信息
     * @return
     */
    @GetMapping("/query")
    public ApiResousUtil<List<DyCommentVO>> query(){
        List<DyCommentVO> selectAll = dyCommentService.selectAll();
        return ApiResousUtil.ok(selectAll);
    }

    /**
     * 新增评论/回复评论
     * @param dyCommentDTO
     * @return
     */
    @PostMapping("/create")
    public ApiResousUtil<String> create(@RequestBody DyCommentDTO dyCommentDTO){
        if (dyCommentDTO.getParentCode() == null) {
            Boolean b = dyCommentService.create(dyCommentDTO);
            if (b == false) {
                return ApiResousUtil.error("没有这个的博客code");
            }
            return ApiResousUtil.ok("评论成功");
        }
        Boolean f = dyCommentService.reply(dyCommentDTO);
        if (f == false) {
            return ApiResousUtil.error("没有父code");
        }
        return ApiResousUtil.ok("回复成功");
    }
}
